<!-- 新增客户 -->
<template>
  <div class="new-customer-dialog">
    <el-dialog
      width="900px"
      class=""
      top="6vh"
      title="新增客户"
      :visible="$store.state.dialog.newCustomer"
      @close="close">
      <el-row>
        <el-col :span="24">
          <el-card shadow="hover">
            <el-form :model="order" :rules="rules" ref="order" label-width="100px" size="mini">
              <el-row :gutter="20">
                <el-col :span="8">
                  <el-form-item label="公司名称" prop="company">
                    <el-input v-model="order.company" auto-complete="off"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="公司地址" prop="address">
                    <el-input v-model="order.address" auto-complete="off"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="公司联系人">
                    <el-input v-model="order.fullName" auto-complete="off"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row :gutter="20">
                <el-col :span="8">
                  <el-form-item label="用户手机号" prop="mobile">
                    <el-input v-model="order.mobile" auto-complete="off"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="联系电话">
                    <el-input v-model="order.phone1"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
            </el-form>
          </el-card>
        </el-col>
      </el-row>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="AddCustomer()" size="mini">新 增</el-button>
        <el-button type="info" @click="close" size="mini">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { AddCustomer } from '../api/customerManagement'
export default {
  data () {
    return {
      order: {},
      rules: {
        company: [
          { required: true, message: '请输入公司名称', trigger: 'blur' }
        ],
        mobile: [
          { required: true, message: '请输入用户手机号', trigger: 'blur' }
        ],
        fullName: [
          { required: true, message: '请输入联系人', trigger: 'blur' }
        ],
        address: [
          { required: true, message: '请输入公司地址', trigger: 'blur' }
        ],
        phone1: [
          { required: true, message: '请输入联系电话', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    // 新增客户
    async AddCustomer () {
      const res = await AddCustomer(this.order)
      if (res.status === 200) {
        this.$notify({
          title: '成功',
          message: res.msg,
          type: 'success'
        })
        this.$parent.getTabeDate()
        this.$store.commit('hide_new_customer_dialog')
      } else {
        this.$notify({
          title: '提示',
          message: res.msg,
          type: 'error'
        })
      }
    },
    close () {
      this.$store.commit('hide_new_customer_dialog')
    }
  }
}
</script>

<style scoped lang="less">

</style>
